package com.jt.config;

import com.jt.vo.SysResult;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//全局异常的处理  应该拦截Controller层
//@ControllerAdvice +@ResponseBody
@RestControllerAdvice//全局异常处理机制，相当于上面两个注解，返回值为json
public class MyExceptionConfig {
//    @ExceptionHandler({RuntimeException.class, SqlSessionException.class})
    @ExceptionHandler(RuntimeException.class)
    public Object handler(Exception exception){
        exception.printStackTrace();//打印报错信息到控制台
    return SysResult.fail();
    }

}
